{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# New in Forest 2 - Running on the QVM\n",
    "\n",
    "PyQuil is for constructing and running quantum programs on real quantum computers. With the release of pyQuil 2, we have changed parts of the API (compared to pyQuil 1.x) to better reflect that focus."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Program construction is largely the same\n",
    "\n",
    "To construct run-and-measure-style programs, there are no changes in program construction. When using explicit `MEASURE` instructions or using parametric programs for massive speed increases, please read about the [new quil memory model](migration3-declare.ipynb).\n",
    "\n",
    "Below, we build a program that constructs a Bell state."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H 0\n",
      "CNOT 0 1\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from pyquil import Program\n",
    "from pyquil.gates import *\n",
    "program = Program(\n",
    "    H(0),\n",
    "    CNOT(0, 1),\n",
    ")\n",
    "print(program)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unphysical methods deprecated in `QVMConnection`\n",
    "\n",
    "In pyQuil 1.x, you would use the `QVMConnection` to run quantum programs on a web-hosted quantum simulator (the \"Quantum Virtual Machine\"). To run on a real quantum processor (QPU), you would switch all instances of `QVMConnection` to `QPUConnection`. However, `QVMConnection` let you do many unphysical operations that are unsupported on a real QPU. These methods are detailed below and have been deprecated in favor of a new API that clearly delineats the physical from the unphysical."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Wavefunction\n",
    "\n",
    "When simulating a quantum program, we can inspect its wavefunction. This is very useful! It is--however--impossible to inspect the wavefunction of a real quantum processor. This is one of the central tenets of quantum information!\n",
    "Attempting to switch instances of `QVMConnection` to `QPUConnection` results in an error. Additionally, using `QVMConnection` with a noise model will cause the `wavefunction` call to behave badly.\n",
    "\n",
    "#### The old way"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0.7071067812+0j)|00> + (0.7071067812+0j)|11>\n"
     ]
    }
   ],
   "source": [
    "from pyquil.api import QVMConnection\n",
    "wfn_old = QVMConnection().wavefunction(program)\n",
    "print(wfn_old)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The new way\n",
    "\n",
    "`WavefunctionSimulator` encapsulates all functionality that requires peering into a wavefunction. This also opens the door for different types of simulators other than those backed by a wavefunction. For example, you can simulate a quantum circuit with a density matrix simulation or a path integral simulation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0.7071067812+0j)|00> + (0.7071067812+0j)|11>\n"
     ]
    }
   ],
   "source": [
    "from pyquil.api import WavefunctionSimulator\n",
    "wfn = WavefunctionSimulator().wavefunction(program)\n",
    "print(wfn)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Expectation\n",
    "\n",
    "Many quantum algorithms involve calculating expectation values of quantum observables. We can represent quantum observables with `PauliSum`s. When using a simulator, it is possible to exactly calculate expectation values (a consequence of having access to the full wavefunction) whereas when running on a QPU you must estimate expectation values by sampling from many runs of a program.\n",
    "\n",
    "Let's use our program defined above to construct a bell state."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H 0\n",
      "CNOT 0 1\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(program)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And we wish to measure the following quantum observables $O$\n",
    " - the expected value of the 0th bit $O=(1-Z_0)/2$\n",
    " - the expected value of the 1st bit $O=(1-Z_1)/2$\n",
    " - the expected value of the exclusive or (XOR) between the two qubits $O=(1-ZZ)/2$\n",
    " \n",
    "**Exercise for the reader:** convince yourself that $(1-ZZ)/2$ is the XOR function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyquil.paulis import sZ\n",
    "\n",
    "z0 = (1-sZ(0))*0.5\n",
    "z1 = (1-sZ(1))*0.5\n",
    "xor = (1-sZ(0)*sZ(1))*0.5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A Bell state is entangled, so each of the 1-qubit operators should give an expectation value of 0.5 (as each qubit taken individually has a 50% change of being measured in the 0 or 1 state) whereas the two-qubit operator should give an expectation value of 0 (as the two qubits considered together will always have even parity)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The old way\n",
    "\n",
    "Because of technical details, `QVMConnection.expectation` requires transforming your observable represented as a `PauliSum` into a program, and then remembering to multiply back in the coefficients. A more usable API was introduced in Pyquil 1.9 and was given the name `pauli_expectation`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0.5+0j)*I + (-0.5+0j)*Z0 \t (0.4999999999999999+0j)\n",
      "(0.5+0j)*I + (-0.5+0j)*Z1 \t (0.4999999999999999+0j)\n",
      "(0.5+0j)*I + (-0.5+0j)*Z0*Z1 \t 0j\n"
     ]
    }
   ],
   "source": [
    "for observable in [z0, z1, xor]:\n",
    "    expectation = QVMConnection().pauli_expectation(prep_prog=program, pauli_terms=observable)\n",
    "    print(observable, '\\t', expectation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The new way\n",
    "If you want analytical expectation values, the solution is to use `WavefunctionSimulator.expectation`\n",
    "\n",
    "Note that the method is not named `pauli_expectation` as we do not support the pyQuil<1.9 way of using `Program`s to represent `PauliSum`s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0.5+0j)*I + (-0.5+0j)*Z0 \t (0.4999999999999999+0j)\n",
      "(0.5+0j)*I + (-0.5+0j)*Z1 \t (0.4999999999999999+0j)\n",
      "(0.5+0j)*I + (-0.5+0j)*Z0*Z1 \t 0j\n"
     ]
    }
   ],
   "source": [
    "for observable in [z0, z1, xor]:\n",
    "    expectation = WavefunctionSimulator().expectation(prep_prog=program, pauli_terms=observable)\n",
    "    print(observable, '\\t', expectation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Sampling expectations on a QPU.\n",
    "\n",
    "Estimating expectation values via *sampling* from a QPU is often something we would like to do! Please look forward for helper functions for sampling observables in the near future."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Async methods removed\n",
    "\n",
    "pyQuil 2 is tailored for Rigetti's Quantum Cloud Services (QCS). In prior releases, executing programs on either the QVM or QPU involved communicating with a cloud-hosted endpoint. Now, you are empowered with\n",
    "\n",
    " 1. A pre-configured quantum machine image (QMI) with your own dedicated qvm and quilc instance.\n",
    " 2. low-latency QPU access all to yourself during a scheduled time window\n",
    " 3. A downloadable local version of the qvm and quilc\n",
    " \n",
    "Taken together, there is no longer any motivation for supporting asynchronous access to either the QVM or QPU."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The old way\n",
    "When running many programs it was often possible to reduce runtime by batching jobs and exploiting the async queue. The following example does not work in pyQuil 2 but gives a sketch about how this would have worked.\n",
    "\n",
    "```python\n",
    "import numpy as np\n",
    "cxn = QVMConnection()\n",
    "thetas = np.linspace(0, 2*np.pi, 20)\n",
    "jobs = [Program(RY(theta, 0)) for theta in thetas]\n",
    "job_ids = [cxn.run_and_measure_async(job, qubits=[0], trials=1000) for job in jobs]\n",
    "bitstrings = [np.asarray(cxn.wait_for_job(job)) for job in jobs]\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The not-quite-new way\n",
    "\n",
    "Since this is such an important use case, there have been many changes to support running many programs as quickly as possible. We demonstrate an equivalent, synchronous version of the example given above. **To idiomatically run this set of jobs, there are additional features you should use that are not covered in this document**. Please continue reading the documentation, especially the page covering [parametric programs](migration3-declare.ipynb)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "cxn = QVMConnection()\n",
    "thetas = np.linspace(0, np.pi, 20)\n",
    "bitstrings = [np.asarray(cxn.run_and_measure(Program(RY(theta, 0)), qubits=[0], trials=1000))\n",
    "              for theta in thetas]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvDW2N/gAAIABJREFUeJzt3Xl8VOW9x/HPLwskLAlLwhaWgAKCAoIB3OVesFKroFQruAButLS2trXeahe13tqitNq63CqCIop6rXgtVYS6oJS2YgIIskXCJiGsQhKWhGzP/SPBhjBDBpjMOTP5vl8vXszMeWbyGyb5cnLOeX6POecQEZHYEud1ASIiEn4KdxGRGKRwFxGJQQp3EZEYpHAXEYlBCncRkRikcBcRiUEKdxGRGKRwFxGJQQlefeG0tDSXmZnp1ZcXEYlKS5cu3eOcS69vnGfhnpmZSU5OjldfXkQkKpnZllDG6bCMiEgMUriLiMQghbuISAxSuIuIxCCFu4hIDKo33M3sOTPbZWargmw3M3vczPLMbKWZDQp/mSIi0e/N5du4YMoHdL/nbS6Y8gFvLt/WYF8rlEshZwJPArOCbP860LPmz1DgTzV/i4jElDeXb2PqglwKCkvo1CqZuy/rzVUDM0J+7r1v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OIdbv98/AgBY1txOBJcC5dcb4Lov8vOf+1cLczrky4MjC3LWNBl6ouf06MNzMAi3554VQ6vc159wiAqyoVctoYJar9jHQysw6Rqa60ITwHnzNObfdObes5vZ+YC3VaxbX5tvPIcT6fa3m3/VAzd3Emj91T1b6Lov8HO6BFuau+01x1MLcwJGFuf0glPoBvlnzq/TrZtYlwHY/C/U9+t15Nb9yv2Nmoa2W7oGaX/UHUr3nWFtUfA7HqR98/hmYWbyZfQrsAt51zgX9DPySRX4O97AtzO2RUGr7K5DpnOsPvMe//+ePFn7+9w/VMqqncw8AngDe9LiegMysBTAH+KFzrrju5gBP8dXnUE/9vv8MnHOVzrmzqV5DeoiZnVVniO8+Az+H+4kszM3xFub2SL31O+e+dM4drrn7LHBOhGoLl1A+I19zzhUf+ZXbOTcPSDSzNI/LOoqZJVIdjLOdc28EGOLrz6G++qPhMzjCOVcIfAiMrLPJd1nk53D3xcLcp6De+uscFx1F9fHIaDIXGF9ztca5QJFzbrvXRZ0IM+tw5NiomQ2h+mfiS2+r+rea2mYAa51zjwYZ5tvPIZT6o+AzSDezVjW3k4ERwLo6w3yXRfUukO0V55OFuU9WiPX/wMxGARVU1z/Rs4IDMLNXqL6SIc3M8oH7qT6ZhHPuaWAe1Vdq5AGHgJu9qTS4EN7DNcBkM6sASoCxXv9Q1nEs7lIwAAAAYElEQVQBcBPwWc0xX4CfAV0hKj6HUOr3+2fQEXjBzOKp/o/nNefcW37PIs1QFRGJQX4+LCMiIidJ4S4iEoMU7iIiMUjhLiISgxTuIiIxSOEuIhKDFO4iIjFI4S4iEoP+H3byDMJ8ht6sAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "averages = [np.mean(bs[:,0]) for bs in bitstrings]\n",
    "_ = plt.plot(thetas, averages, 'o-')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
